﻿using System.Data.Common;
using Autofac;
using Zinnia.Lite.Context;
using Zinnia.Lite.Core;
using Zinnia.Lite.Repository;
using Zinnia.Lite.Repository.Imp;

namespace Zinnia.Lite.Injection.Imp
{
    /// <summary>
    /// 数据库依赖注入器
    /// </summary>
    public class DataDependencyRegistrar : IDependencyRegistrar
    {
        /// <summary>
        /// 类型依赖注册（数据库连接在请求生命周期结束后释放）
        /// </summary>
        /// <param name="builder">注册容器</param>
        public void Register(ContainerBuilder builder,ITypeService typeFinder)
        {
            builder.Register<IEfBaseContext>(c => new ZinniaEfBaseContext()).InstancePerLifetimeScope();
            builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>)).InstancePerLifetimeScope();
        }

        /// <summary>
        /// 排序
        /// </summary>
        public int Order
        {
            get { return -10; }
        }
    }
}
